﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HZ.Supervise.Model;

namespace HZ.Supervise.Web.Message
{
    public partial class MessageListForTypeAll : System.Web.UI.Page
    {
        IBLL.IBLL_MessageTypeDetail ibllMessage = new BLL.BLL_MessageTypeDetail();
        DataTable dt;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["query"] = URLUtil.GetSuperviseQueryFromURL(Request);
                BindList();
            }

        }
        /// <summary>
        /// 数据绑定
        /// </summary>
        void BindList()
        {

            int t = 0;
            Model.Message message = new HZ.Supervise.Model.Message();

            if (Request.QueryString["Is_Read"] == "1")//未查看的
            {
                message.Name = txtName.Text.Trim();
                message.CreatTime = txtCreatTime.Text.Trim();
                message.AreaName = txtAreaName.Text.Trim();
                message.HospitalName = txtHospitalName.Text.Trim();
                message.UserId = CurrentAccount.UserID.ToString();
                dt = ibllMessage.GetMessage(message, true, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out t);
                gvwMessageList.DataSource = dt;
                gvwMessageList.DataBind();
                AspNetPager1.RecordCount = t;
            }
            else//已经查看的
            {
                message.Name = txtName.Text.Trim();
                message.CreatTime = txtCreatTime.Text.Trim();
                message.AreaName = txtAreaName.Text.Trim();
                message.HospitalName = txtHospitalName.Text.Trim();
                message.UserId = CurrentAccount.UserID.ToString();
                dt = ibllMessage.GetMessage(message, false, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out t);
                gvwMessageList.DataSource = dt;
                gvwMessageList.DataBind();
                AspNetPager1.RecordCount = t;
              
            }

        }


        protected void gvwProcureCatalog_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "DirectByDetail")
            {

                string sessionid = Guid.NewGuid().ToString();

                SuperviseQuery query = (SuperviseQuery)ViewState["query"];
                query.Append = "";
                Session[sessionid] = query;
                string url="";
                if (e.CommandArgument.ToString().Trim()=="1")
                {
                    url = "MessageFinalDetailForType1.aspx";
                }
                if (e.CommandArgument.ToString().Trim() == "2")
                {
                    url = "MessageFinalDetailForType2.aspx";
                }
                if (e.CommandArgument.ToString().Trim() == "3")
                {
                    url = "MessageFinalDetailForType3.aspx";
                }
                if (e.CommandArgument.ToString().Trim() == "4")
                {
                    url = "MessageFinalDetailForType4.aspx";
                }
                if (e.CommandArgument.ToString().Trim() == "5")
                {
                    url = "MessageFinalDetailForType5.aspx";
                }
                if (e.CommandArgument.ToString().Trim() == "6")
                {
                    url = "MessageFinalDetailForType6.aspx";
                }
                if (e.CommandArgument.ToString().Trim() == "7")
                {
                    url = "MessageFinalDetailForType7.aspx";
                }
                if (e.CommandArgument.ToString().Trim() == "8")
                {
                    url = "MessageFinalDetailForType8.aspx";
                }
                if (e.CommandArgument.ToString().Trim() == "9")
                {
                    url = "MessageFinalDetailForType9.aspx";
                }
                if (e.CommandArgument.ToString().Trim() == "10")
                {
                    url = "MessageFinalDetailForType10.aspx";
                }
                if (e.CommandArgument.ToString().Trim() == "11")
                {
                    url = "MessageFinalDetailForType11.aspx";
                }
                if (e.CommandArgument.ToString().Trim() == "12")
                {
                    url = "MessageFinalDetailForType12.aspx";
                }
                if (e.CommandArgument.ToString().Trim() == "13")
                {
                    url = "MessageFinalDetailForType13.aspx";
                }
                if (e.CommandArgument.ToString().Trim() == "14")
                {
                    url = "MessageFinalDetailForType14.aspx";
                }

                GridViewRow row = ((Control)e.CommandSource).NamingContainer as GridViewRow;
                string _strMessageId = Convert.ToString(this.gvwMessageList.DataKeys[row.RowIndex].Value);
                string _strTypeId = e.CommandArgument.ToString();
                ibllMessage.SetMessageIsRead(_strMessageId);//设置此消息为已读

                //根据MessageTypeDetailId取得where条件
                string _strSqlStringWhere = ibllMessage.GetMessageTypeDeatilSqlStringWhere(_strMessageId);
                string _strSqlStringHaving = ibllMessage.GetMessageTypeDeatilSqlStringHaving(_strMessageId);
                query.SqlStringWhere = _strSqlStringWhere;
                query.Append = _strSqlStringHaving;//暂时用下
                Response.Redirect(string.Format("{0}?sessionid={1}", url, sessionid));

            }
        }
        /// <summary>
        /// 字符串截取
        /// </summary>
        /// <param name="sString"></param>
        /// <param name="nLeng"></param>
        /// <returns></returns>
        string SubStr(string sString, int nLeng)
        {
            if (sString.Length <= nLeng)
            {
                return sString;
            }
            string sNewStr = sString.Substring(0, nLeng);
            sNewStr = sNewStr + "...";
            return sNewStr;
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindList();
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            BindList();
        }
    }
}
